package com.nameless.controller.api;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nameless.annotation.MyLog;
import com.nameless.entity.OperLog;
import com.nameless.service.OperLogService;
import com.nameless.vo.LogVo;
import com.nameless.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : 陈灰灰
 * @Date: 2023/02/27/19:27
 * @Description:
 */
@Api(value = "/system/api/operLog", tags = {"操作日志控制层"})
@RestController
@RequestMapping("/system/api/operLog")
public class ApiOperLogController {
    @Autowired
    private OperLogService operLogService;

    /**
     * @Author chh
     * 查询所有日志
     * @param logVo 日志签证官
     * @return {@link Result}
     */
   @ApiImplicitParams({
           @ApiImplicitParam(paramType = "query", dataType = "LogVo", name = "logVo", value = "日志签证官", required = true)
   })
   @ApiOperation(value = "查询所有日志", notes = "查询所有日志")
   @RequestMapping("queryAllLogs")
   @MyLog(title = "queryAllLogs",businessType = 0)
    public Result queryAllLogs(LogVo logVo){
        System.out.println(logVo);
        Page<OperLog> page = new Page<>(logVo.getPageNo(), logVo.getPageSize());
        LambdaQueryWrapper<OperLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(logVo.getTitle()),OperLog::getTitle,logVo.getTitle());
        queryWrapper.orderByAsc(OperLog::getOperId);
        Page<OperLog> page1 = operLogService.page(page, queryWrapper);
        return new Result(200,"查询成功",page1);

    }

    /**
     * @Author chh
     * 删除日志
     * @param operId ③id
     * @return {@link Result}
     */
   @ApiImplicitParams({
           @ApiImplicitParam(paramType = "query", dataType = "int", name = "operId", value = "③id", required = true)
   })
   @ApiOperation(value = "删除日志", notes = "删除日志")
   @RequestMapping("delete")
   @MyLog(title = "delete操作",businessType = 3)
    public Result delete(Integer operId){
        System.out.println(operId);
        boolean b = operLogService.removeById(operId);
        return new Result(200,"删除成功");
    }


}
